package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 图片素材控制
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/material")
@RequiredArgsConstructor
public class WmMaterialController {


    private final WmMaterialService wmMaterialService;

    /**
     * 上传图片
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {

        log.info("图片上传.....{}",multipartFile);

        return wmMaterialService.uploadPicture(multipartFile);
    }


    /**
     * 查看素材列表
     * @param wmMaterialDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult findList(@RequestBody WmMaterialDto wmMaterialDto) {

        log.info("查看素材列表：.....{}",wmMaterialDto);

        return wmMaterialService.findList(wmMaterialDto);
    }


    /**
     * 图片删除
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable Integer id) {

        log.info("图片删除...{}",id);

        return wmMaterialService.deleteImageById(id);
    }


    /**
     * 收藏
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collectById(@PathVariable Integer id) {

        log.info("收藏图片...{}",id);

        return wmMaterialService.collectById(id);
    }



    /**
     * 取消收藏
     * @param id
     * @return
     */
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollectById(@PathVariable Integer id) {

        log.info("取消收藏图片...{}",id);

        return wmMaterialService.cancelCollectById(id);

    }

}




















